package com.woniuxy.company5.service.impl;


import com.woniuxy.company5.entity.UserPermission;
import com.woniuxy.company5.mapper.UserPermissionMapper;
import com.woniuxy.company5.service.UserPermissionService;

import com.woniuxy.company5.vo.TreeNode;
import com.woniuxy.company5.vo.UserPermissionVo;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * @author ：fengsir
 * @date ：Created in 2022/12/7 10:09
 * @description：
 * @modified By：
 * @version: $
 */

@Service
public class UserPermissionServiceImpl implements UserPermissionService {
    @Resource
    private UserPermissionMapper userPermissionMapper;

    @Override
    public List<String> selectByAccount(String account) {
        return userPermissionMapper.selectByAccount(account);
    }

    @Override
    public List<TreeNode> getPermissionByParentId(Integer fatherId) {
        List<TreeNode> permissionByParentId = userPermissionMapper.getPermissionByParentId(fatherId);
        //如果permissions不为空，迭代当前集合
        if(permissionByParentId!=null && permissionByParentId.size()>0){
            for (TreeNode permission: permissionByParentId ) {
                //得到当前对象下的所有子菜单
                List<TreeNode> subPermissions = getPermissionByParentId(permission.getId());
                permission.setChildren(subPermissions);
            }
        }
        return permissionByParentId;
    }

    @Override
    public List<Integer> getPermissionByRole(Integer id) {
        return userPermissionMapper.getPermissionByRole(id);
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return 0;
    }

    @Override
    public int insert(UserPermission record) {
        return 0;
    }

    @Override
    public int insertSelective(UserPermission record) {
        return 0;
    }

    @Override
    public UserPermission selectByPrimaryKey(Long id) {
        return null;
    }

    @Override
    public int updateByPrimaryKeySelective(UserPermission record) {
        return 0;
    }

    @Override
    public int updateByPrimaryKey(UserPermission record) {
        return 0;
    }
    @Override
    public List<UserPermissionVo> selectMenu(Integer fatherId) {
        List<UserPermissionVo> permissionVos = userPermissionMapper.selectMenu(fatherId);
        if (permissionVos != null) {
            for (UserPermissionVo permissionVo : permissionVos) {
                List<UserPermissionVo> permissionVos1 = selectMenu(permissionVo.getId());
                permissionVo.setChildren(permissionVos1);
            }
        }
        return permissionVos;

    }
}
